
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>django.contrib.postgres &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../search.html" />
    <link rel="next" title="PostgreSQL 特有聚合函数" href="aggregates.html" />
    <link rel="prev" title="消息框架" href="../messages.html" />



 
<script src="../../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="../messages.html" title="消息框架">previous</a>
     |
    <a href="../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="aggregates.html" title="PostgreSQL 特有聚合函数">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-postgres-index">
            
  <div class="section" id="s-module-django.contrib.postgres">
<span id="s-django-contrib-postgres"></span><span id="module-django.contrib.postgres"></span><span id="django-contrib-postgres"></span><h1><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres</span></code><a class="headerlink" href="#module-django.contrib.postgres" title="永久链接至标题">¶</a></h1>
<p>PostgreSQL 有许多 Django 支持的数据库所不具备的特性。这个可选的模块包含了一些 PostgreSQL 特有数据类型的模型字段和表单字段。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p>Django 是，并将继续是一个与数据库无关的网络框架。我们鼓励那些为 Django 社区编写可重用的应用程序的人，在可行的情况下编写数据库无关的代码。然而，我们也认识到，在现实世界中，使用 Django 编写的项目不一定是数据库无关的。事实上，一旦一个项目达到一定的规模，改变底层数据存储已经是一个重大的挑战，很可能需要通过一些方式改变代码库来处理数据存储之间的差异。</p>
<p class="last">Django 提供了对一些数据类型的支持，这些数据类型只能在 PostgreSQL 中使用。除了 PostgreSQL 在支持的数据库中拥有最丰富的功能，所以它的用户可以获得最大的收益之外，没有任何根本的原因（例如）不存在 <code class="docutils literal notranslate"><span class="pre">contrib.mysql</span></code> 模块。</p>
</div>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="aggregates.html">PostgreSQL 特有聚合函数</a><ul>
<li class="toctree-l2"><a class="reference internal" href="aggregates.html#general-purpose-aggregation-functions">通用聚合函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="aggregates.html#aggregate-functions-for-statistics">统计的聚合功能</a></li>
<li class="toctree-l2"><a class="reference internal" href="aggregates.html#usage-examples">使用实例：</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="constraints.html">PostgreSQL 特有数据库约束</a><ul>
<li class="toctree-l2"><a class="reference internal" href="constraints.html#exclusionconstraint"><code class="docutils literal notranslate"><span class="pre">ExclusionConstraint</span></code></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="fields.html">PostgreSQL 特有模型字段</a><ul>
<li class="toctree-l2"><a class="reference internal" href="fields.html#indexing-these-fields">对这些字段进行索引</a></li>
<li class="toctree-l2"><a class="reference internal" href="fields.html#arrayfield"><code class="docutils literal notranslate"><span class="pre">ArrayField</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="fields.html#citext-fields"><code class="docutils literal notranslate"><span class="pre">CIText</span></code> 字段</a></li>
<li class="toctree-l2"><a class="reference internal" href="fields.html#hstorefield"><code class="docutils literal notranslate"><span class="pre">HStoreField</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="fields.html#jsonfield"><code class="docutils literal notranslate"><span class="pre">JSONField</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="fields.html#range-fields">范围字段</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="forms.html">PostgreSQL 特有表单字段和部件</a><ul>
<li class="toctree-l2"><a class="reference internal" href="forms.html#fields">字段</a></li>
<li class="toctree-l2"><a class="reference internal" href="forms.html#widgets">部件</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="functions.html">PostgreSQL 特有数据库函数</a><ul>
<li class="toctree-l2"><a class="reference internal" href="functions.html#randomuuid"><code class="docutils literal notranslate"><span class="pre">RandomUUID</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#transactionnow"><code class="docutils literal notranslate"><span class="pre">TransactionNow</span></code></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="indexes.html">PostgreSQL 特有模型索引</a><ul>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#bloomindex"><code class="docutils literal notranslate"><span class="pre">BloomIndex</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#brinindex"><code class="docutils literal notranslate"><span class="pre">BrinIndex</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#btreeindex"><code class="docutils literal notranslate"><span class="pre">BTreeIndex</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#ginindex"><code class="docutils literal notranslate"><span class="pre">GinIndex</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#gistindex"><code class="docutils literal notranslate"><span class="pre">GistIndex</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#hashindex"><code class="docutils literal notranslate"><span class="pre">HashIndex</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#spgistindex"><code class="docutils literal notranslate"><span class="pre">SpGistIndex</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="indexes.html#opclass-expressions"><code class="docutils literal notranslate"><span class="pre">OpClass()</span></code> 表达式</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="lookups.html">PostgreSQL 特有查找</a><ul>
<li class="toctree-l2"><a class="reference internal" href="lookups.html#trigram-similarity">三元相似度</a></li>
<li class="toctree-l2"><a class="reference internal" href="lookups.html#unaccent"><code class="docutils literal notranslate"><span class="pre">Unaccent</span></code></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="operations.html">数据库迁移操作</a><ul>
<li class="toctree-l2"><a class="reference internal" href="operations.html#creating-extension-using-migrations">使用迁移创建扩展</a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#createextension"><code class="docutils literal notranslate"><span class="pre">CreateExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#bloomextension"><code class="docutils literal notranslate"><span class="pre">BloomExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#btreeginextension"><code class="docutils literal notranslate"><span class="pre">BtreeGinExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#btreegistextension"><code class="docutils literal notranslate"><span class="pre">BtreeGistExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#citextextension"><code class="docutils literal notranslate"><span class="pre">CITextExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#cryptoextension"><code class="docutils literal notranslate"><span class="pre">CryptoExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#hstoreextension"><code class="docutils literal notranslate"><span class="pre">HStoreExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#trigramextension"><code class="docutils literal notranslate"><span class="pre">TrigramExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#unaccentextension"><code class="docutils literal notranslate"><span class="pre">UnaccentExtension</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#managing-collations-using-migrations">使用迁移来管理整理</a></li>
<li class="toctree-l2"><a class="reference internal" href="operations.html#concurrent-index-operations">并发索引操作</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="search.html">全文搜索</a><ul>
<li class="toctree-l2"><a class="reference internal" href="search.html#the-search-lookup"><code class="docutils literal notranslate"><span class="pre">search</span></code> 查找</a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#searchvector"><code class="docutils literal notranslate"><span class="pre">SearchVector</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#searchquery"><code class="docutils literal notranslate"><span class="pre">SearchQuery</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#searchrank"><code class="docutils literal notranslate"><span class="pre">SearchRank</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#searchheadline"><code class="docutils literal notranslate"><span class="pre">SearchHeadline</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#changing-the-search-configuration">更改搜索配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#weighting-queries">加权查询</a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#performance">性能</a></li>
<li class="toctree-l2"><a class="reference internal" href="search.html#trigram-similarity">三元相似度</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="validators.html">验证器</a><ul>
<li class="toctree-l2"><a class="reference internal" href="validators.html#keysvalidator"><code class="docutils literal notranslate"><span class="pre">KeysValidator</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="validators.html#range-validators">范围验证器</a></li>
</ul>
</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="../messages.html"
                        title="上一章">消息框架</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="aggregates.html"
                        title="下一章">PostgreSQL 特有聚合函数</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/ref/contrib/postgres/index.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="../messages.html" title="消息框架">previous</a>
     |
    <a href="../../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="aggregates.html" title="PostgreSQL 特有聚合函数">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>